package com.gmall.web.controller;

import com.gmall.web.model.Clazz;
import com.gmall.web.model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/")
public class TestFTLController {

    @GetMapping("test")
    public String test(Model model){

        //test2109A
        //View 查找 templates/test2109A.ftl
        /**
         * spring:
         *   freemarker:
         *     template-loader-path: classpath:/templates/
         *     suffix: .ftl
         */

        model.addAttribute("title","测试DEMO");
        model.addAttribute("name","zhangsan");
        model.addAttribute("message","Hello, World!");
        //model.addAttribute("success",1);
        model.addAttribute("aaa","999999999999999999999");
        List studentList_2019A = new ArrayList();
        studentList_2019A.add(new Student("zhangsan",18,"2109A"));
        studentList_2019A.add(new Student("lisi",23,"2109A"));
        studentList_2019A.add(new Student("wangwu",21,"2109A"));
        studentList_2019A.add(new Student("zhaoliu",25,"2109A"));

        List studentList_2019B = new ArrayList();
        studentList_2019B.add(new Student("zhangsan1",18,"2109B"));
        studentList_2019B.add(new Student("lisi1",23,"2109B"));
        studentList_2019B.add(new Student("wangwu1",21,"2109B"));
        studentList_2019B.add(new Student("zhaoliu1",25,"2109B"));

        List<Clazz> clazzList = new ArrayList();
        Clazz clazz_2109A = new Clazz();
        clazz_2109A.setName("2009A");
        clazz_2109A.setStudentList(studentList_2019A);
        Clazz clazz_2109B = new Clazz();
        clazz_2109B.setName("2009B");
        clazz_2109B.setStudentList(studentList_2019B);

        clazzList.add(clazz_2109A);
        clazzList.add(clazz_2109B);
        model.addAttribute("clazzList",clazzList);

        model.addAttribute("today",new java.util.Date());
        model.addAttribute("point",123456.87559);

        return "test/test2109A";
    }
}
